﻿using AiXiu.BLL;
using AiXiu.IBLL;
using System.Web;

namespace AiXiu.WebSite
{
    /// <summary>
    /// 视频点赞一般处理程序
    /// </summary>
    public class VideoLikeHandler : IHttpHandler
    {
        /// <summary>
        /// 处理请求
        /// </summary>
        /// <param name="context"></param>
        public void ProcessRequest(HttpContext context)
        {
            // 接收参数
            string videoId = context.Request.QueryString["videoId"];
            string userIdStr = context.Request.QueryString["userId"];
            string action = context.Request.QueryString["action"];
            if(!string.IsNullOrWhiteSpace(videoId) &&
                !string.IsNullOrWhiteSpace(userIdStr) &&
                !string.IsNullOrWhiteSpace(action))
            {
                // 执行操作
                int userId = int.Parse(userIdStr);
                ILikeManager likeManager = new LikeManager();
                switch (action)
                {
                    case "add":
                        likeManager.AddLike(videoId, userId);
                        break;
                    case "remove":
                        likeManager.RemoveLike(videoId, userId);
                        break;
                    default:
                        break;
                }
            }

            // 输出结果
            context.Response.ContentType = "text/plain";
            context.Response.Write("ok");
            context.Response.End();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}